<template>
  <div class="boder">
   
    <label>选择科目</label>
    <el-select v-model="value" placeholder="请选择">
      <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"></el-option>
    </el-select>
    <label class="left">作业类型</label>
    <el-select v-model="job_type" placeholder="请选择">
      <el-option v-for="item in times" :key="item.value" :label="item.label" :value="item.value"></el-option>
    </el-select>
  
    <label class="left" >选择班级</label>
  <el-cascader
    v-model="value1"
    :options="classes"
    :props="{ expandTrigger: 'hover' }"
    @change="handleChange">
    </el-cascader>

    <div class="top">
      <label>选择题</label>
      <el-input class="inputwidth" placeholder="请输入题型数量" v-model="choose" clearable></el-input>

      <label class="left2">完形填空</label>

      <el-input class="inputwidth" placeholder="请输入题型数量" v-model="completion" clearable></el-input>
      <label class="left2">解答题</label>

      <el-input class="inputwidth" placeholder="请输入题型数量" v-model="answer_questions" clearable></el-input>
      <label class="left2">作文</label>

      <el-input class="inputwidth" placeholder="请输入题型数量" v-model="composition" clearable></el-input>
    </div>
    <el-row>
      <el-button class="submit" type="primary" @click="submitquestion">发布作业</el-button>
    </el-row>
  </div>
</template>
<script>

export default {
  data() {
    return {
      options: [
        {
          value: "语文",
          label: "语文"
        },
        {
          value: "数学",
          label: "数学"
        },
        {
          value: "外语",
          label: "外语"
        },
        {
          value: "政治",
          label: "政治"
        },
        {
          value: "历史",
          label: "历史"
        },
        {
          value: "地理",
          label: "地理"
        },
        {
          value: "物理",
          label: "物理"
        },
        {
          value: "化学",
          label: "化学"
        },
        {
          value: "生物",
          label: "生物"
        }
      ],
      value: "",
      choose: "",
      completion: "",
      answer_questions: "",
      composition: "",
      times: [
        {
          value: "课后作业",
          label: "课后作业"
        },
        {
          value: "周末作业",
          label: "周末作业"
        },
        {
          value: "寒暑假作业",
          label: "寒暑假作业"
        }
      ],
      job_type: "",
     
        
         value1: [],
         classes: [{
          value: '',
          label: '高一',
          children: [{
            value: '1',
            label: '1班',
            
          },{
            value: '2',
            label: '2班',
            
          },{
            value: '3',
            label: '3班',
            
          },{
            value: '4',
            label: '4班',
            
          },{
            value: '5',
            label: '5班',
            
          },{
            value: '6',
            label: '6班',
            
          }]
        },
        {
          value: '',
          label: '高二',
          children: [{
            value: '7',
            label: '1班',
            
          },{
            value: '8',
            label: '2班',
            
          },{
            value: '9',
            label: '3班',
            
          },{
            value: '10',
            label: '4班',
            
          },{
            value: '11',
            label: '5班',
            
          },{
            value: '12',
            label: '6班',
            
          },{
            value: '13',
            label: '7班',
            
          },{
            value: '14',
            label: '8班',
            
          }]
        },
         {
          value: '',
          label: '高三',
          children: [{
            value: '15',
            label: '1班',
            
          },{
            value: '16',
            label: '2班',
            
          },{
            value: '17',
            label: '3班',
            
          },{
            value: '18',
            label: '4班',
            
          },{
            value: '19',
            label: '5班',
            
          },{
            value: '20',
            label: '6班',
            
          },{
            value: '21',
            label: '7班',
            
          },{
            value: '22',
            label: '8班',
            
          },{
            value: '23',
            label: '9班',
            
          }]
        }
        ],
        cla: ""
         }
    },

  methods: {
      handleChange(value1) {
      //console.log(value1[1]);
      this.cla=value1[1]
      },
    submitquestion() {
      // console.log(this.value);
       console.log(this.value);
     
      const h = this.$createElement;
      this.$msgbox({
        title: "确认提示",
        message:"你确认发布作业吗"
        ,
        showCancelButton: true,
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        beforeClose: (action, instance, done) => {
          if (action === "confirm") {
            instance.confirmButtonLoading = true;
            instance.confirmButtonText = "执行中...";
           
           this.$axios.get("http://localhost:8080/teacher/assign_homework",
                //get请求参数
              {params:{
              subject: this.value,
              chooseNumber:this.choose,
              completionNumber: this.completion,
              answer_questionsNumber: this.answer_questions,
              compositionNumber:this.composition,
              job_type:this.job_type,
              c_id:this.cla
              }}
              
                ).then(resp=>{
                    
                    this.message=resp.data
                });


            setTimeout(() => {
              done();
              setTimeout(() => {
                instance.confirmButtonLoading = false;
              }, 300);
            }, 1000);        
          } else {
            done();
          }
        }
      })
      .then(action => {
       if(this.message==200){
          this.$message({
         message:"发布成功！",
        type: "success"
        });
       }
       else{
          this.$message({
         message:"发布失败，请重新发布！",
       
        });
       }
      });
    }
  }
};
</script>
<style scoped>
.inputwidth {
  width: 150px;
}
.left {
  padding-left: 150px;
}
.top {
  padding-top: 100px;
}
.left2 {
  padding-left: 80px;
}
.submit {
  margin: 150px 500px;
}
.boder {
  border: 1px beige solid;
}
</style>
